<template>
  <footer class="footer">
    <span class="todo-count"
      >剩余<strong>{{ lastNum }}</strong></span
    >
    <ul class="filters">
      <li>
        <a
          :class="{ selected: type === 'all' }"
          href="javascript:;"
          @click="changeType('all')"
          >全部</a
        >
      </li>
      <li>
        <a
          :class="{ selected: type === 'No' }"
          href="javascript:;"
          @click="changeType('No')"
          >未完成</a
        >
      </li>
      <li>
        <a
          :class="{ selected: type === 'Done' }"
          href="javascript:;"
          @click="changeType('Done')"
          >已完成</a
        >
      </li>
    </ul>
    <button class="clear-completed" @click="delDone">清除已完成</button>
  </footer>
</template>

<script>
import { mapActions, mapGetters, mapMutations, mapState } from "vuex";
export default {
  computed: {
    ...mapState("todos", ["type"]),
    ...mapGetters("todos", ["newList"]),

    lastNum() {
      return this.newList.filter((item) => !item.isDone).length;
    },
  },

  methods: {
    ...mapMutations("todos", ["changeType"]),
    ...mapActions("todos", ["delDoneAsync"]),

    delDone() {
      this.delDoneAsync({ newList: this.newList });
    },
  },
};
</script>
